import { Style, Text, Fill, Stroke } from 'ol/style';

export class BubbleTextStyle extends Style {
	/**
	 *
	 * @param options
	 * : {
	 * 		text: string;
	 * 		fontSize?: number;
	 * 		padding?: number[];
	 * 		backgroundColor?: string;
	 * 		textColor?: string;
	 * 		strokeColor?: string;
	 * 		strokeWidth?: number;
	 * 		offsetY?: number;
	 * 	}
	 */
	constructor(options) {
		const {
			text,
			fontSize = 14,
			padding = [5, 10, 5, 10], // [top, right, bottom, left]
			backgroundColor = 'white',
			textColor = 'black',
			strokeColor = '#333',
			strokeWidth = 1,
			offsetY = -20
		} = options;

		// 创建文本样式
		const textStyle = new Text({
			text,
			font: `${fontSize}px Arial`,
			fill: new Fill({
				color: textColor
			}),
			stroke: new Stroke({
				color: strokeColor,
				width: strokeWidth
			}),
			padding: padding,
			backgroundFill: new Fill({
				color: backgroundColor
			}),
			backgroundStroke: new Stroke({
				color: strokeColor,
				width: strokeWidth
			}),
			offsetY: offsetY
		});

		super({
			text: textStyle
		});
	}
}